home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-11 | 9.0 KB | 347 lines | [TEXT/MPS ] |
- /*
- File: CappuccinoPromise.cpp
-
- Contents: Classes to encapsulate promises.
-
- Written by: Troy Gaul
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- */
-
- // -- Compiler/Preprocessor Switches --
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (eg. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with the "ev" parameter set.
- #include <Except.h>
- #endif
-
- // -- Cappuccino Includes --
-
- #ifndef _CAPPUCCINOPROMISE_
- #include "CappuccinoPromise.h"
- #endif
-
- #ifndef _CAPPUCCINO_
- #include "Cappuccino.h"
- #endif
-
- #ifndef _CAPPUCCINOCONTENT_
- #include "CappuccinoContent.h"
- #endif
-
- #ifndef _CAPPUCCINODEF_
- #include "CappuccinoDef.h"
- #endif
-
- #ifndef _CAPPUCCINOGLOBALS_
- #include "CappuccinoGlobals.h"
- #endif
-
- #ifndef _SAMPLECOLLECTIONS_
- #include "SampleCollections.h"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _BARRAY_
- #include <BArray.h>
- #endif
-
- #ifndef _ODDEBUG_
- #include <ODDebug.h>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
-
- //------------------------------------------------------------------------------
- // SCappuccinoPromiseData
- //------------------------------------------------------------------------------
-
- struct SCappuccinoPromiseData
- {
- CPromise* fPromise;
- };
-
- //==============================================================================
- // CPromiseSet
- //==============================================================================
- #pragma mark • CPromiseSet •
-
- //------------------------------------------------------------------------------
- // Function: Constructor
- // Origin: CPromiseSet
- //------------------------------------------------------------------------------
-
- CPromiseSet::CPromiseSet()
- {
- fPromiseList = kODNULL;
-
- fPromiseList = new CList;
- }
-
- //------------------------------------------------------------------------------
- // Function: Destructor
- // Origin: CPromiseSet
- //------------------------------------------------------------------------------
-
- CPromiseSet::~CPromiseSet()
- {
- // Remove and release our promise objects.
- if ( fPromiseList )
- {
- Environment* ev = somGetGlobalEnvironment();
-
- TRY
- this->Clear(ev);
- CATCH_ALL
- ENDTRY
-
- ODDeleteObject(fPromiseList);
- }
- }
-
- //------------------------------------------------------------------------------
- // Function: Clear
- // Origin: CPromiseSet
- //------------------------------------------------------------------------------
-
- void CPromiseSet::Clear( Environment* ev )
- {
- CListIterator fiter(fPromiseList);
- for ( CPromise* promise = (CPromise*) fiter.First();
- fiter.IsNotComplete(); promise = (CPromise*) fiter.Next() )
- {
- fiter.RemoveCurrent();
- delete promise;
- }
- }
-
- //------------------------------------------------------------------------------
- // Function: Add
- // Origin: CPromiseSet
- //------------------------------------------------------------------------------
-
- void CPromiseSet::Add( Environment* ev,
- CPromise* promise )
- {
- ASSERT_NOT_NULL(promise);
- fPromiseList->Add(promise);
- }
-
- //==============================================================================
- // CPromise
- //==============================================================================
- #pragma mark • CPromise •
-
- //------------------------------------------------------------------------------
- // Function: Constructor
- // Origin: CPromise
- //------------------------------------------------------------------------------
-
- CPromise::CPromise( Cappuccino* part )
- {
- fPart = part;
- fIsClipboardPromise = kODFalse;
- fUpdateID = kODNULLID;
- fFulfilled = kODFalse;
- }
-
- //------------------------------------------------------------------------------
- // Function: Destructor
- // Origin: CPromise
- //------------------------------------------------------------------------------
-
- CPromise::~CPromise()
- {
- }
-
- //------------------------------------------------------------------------------
- // Function: PromiseTo
- // Origin: CPromise
- //------------------------------------------------------------------------------
-
- void CPromise::PromiseTo( Environment* ev,
- ODStorageUnit* su)
- {
- }
-
- //------------------------------------------------------------------------------
- // Function: Fulfill
- // Origin: CPromise
- //------------------------------------------------------------------------------
-
- void CPromise::Fulfill( Environment* ev,
- ODStorageUnitView* promiseSUView )
- {
- WASSERT(!fFulfilled);
-
- fFulfilled = kODTrue;
- }
-
- //------------------------------------------------------------------------------
- // Function: CreateActionData
- // Origin: CPromise
- //
- // Description: This method is called when this promise must be encapsulated
- // into a byte array.
- //------------------------------------------------------------------------------
-
- ODByteArray* CPromise::CreatePromiseData()
- {
- SCappuccinoPromiseData data;
- data.fPromise = this;
-
- return CreateByteArray(&data, sizeof data);
- }
-
- //------------------------------------------------------------------------------
- // Function: GetPromiseFromByteArray [static]
- // Origin: CPromise
- //
- // Description: This method is called when ...
- //------------------------------------------------------------------------------
-
- CPromise* CPromise::GetPromiseFromByteArray( ODByteArray* promise )
- {
- ASSERT_NOT_NULL(promise);
- ASSERT_NOT_NULL(promise->_buffer);
-
- return ((SCappuccinoPromiseData*) promise->_buffer)->fPromise;
- }
-
- //------------------------------------------------------------------------------
- // Function: GetPromiseFromSUView [static]
- // Origin: CPromise
- //
- // Description: This method is called when Fulfill promise has been called on
- // a promised storage unit.
- //
- // NOTE: This function will only work when this function is
- // called in the handling of a call to the part's FulfillPromise
- // method.
- //------------------------------------------------------------------------------
-
- CPromise* CPromise::GetPromiseFromSUView( Environment* ev,
- ODStorageUnitView* suView )
- {
- ASSERT_NOT_NULL(suView);
-
- // Since this is made to be used by Fulfill promise, the flag indicating
- // that this is a promise value should have been removed by now (by
- // OpenDoc before calling ODPart::FulfillPromise to prevent recursion).
- // If this were still marked as a promise value, the GetValue call below
- // would cause the promise to be fulfilled, which may cause an infinite
- // recursion.
- WASSERT(!suView->IsPromiseValue(ev));
-
- ODByteArray data;
- suView->GetValue(ev, sizeof(SCappuccinoPromiseData), &data);
-
- return CPromise::GetPromiseFromByteArray(&data);
- }
-
-
- //==============================================================================
- // CCappuccinoContentPromise
- //==============================================================================
- #pragma mark • CCappuccinoContentPromise •
-
- //------------------------------------------------------------------------------
- // Function: Constructor
- // Origin: CCappuccinoContentPromise
- //------------------------------------------------------------------------------
-
- CCappuccinoContentPromise::CCappuccinoContentPromise( Cappuccino* part,
- CCappuccinoContent* content,
- ODValueType valueType )
- : CPromise(part)
- {
- ASSERT_NOT_NULL(content);
- ASSERT_NOT_NULL(valueType);
-
- fContent = kODNULL;
- fValueType = kODNULL;
-
- fContent = content;
- fContent->Acquire();
-
- fValueType = valueType;
- }
-
- //------------------------------------------------------------------------------
- // Function: Destructor
- // Origin: CCappuccinoContentPromise
- //------------------------------------------------------------------------------
-
- CCappuccinoContentPromise::~CCappuccinoContentPromise()
- {
- fContent->Release();
- }
-
- //------------------------------------------------------------------------------
- // Function: PromiseTo
- // Origin: CCappuccinoContentPromise
- //------------------------------------------------------------------------------
-
- void CCappuccinoContentPromise::PromiseTo( Environment* ev,
- ODStorageUnit* su )
- {
- ASSERT_NOT_NULL(su);
-
- TempODByteArray data = this->CreatePromiseData();
-
- su->Focus(ev, kODPropContents, kODPosUndefined, kODNULL, 0, kODPosAll);
- su->SetPromiseValue(ev, fValueType, 0, data, fPart->GetODPart());
-
- Inherited::PromiseTo(ev, su);
- }
-
- //------------------------------------------------------------------------------
- // Function: Fulfill
- // Origin: CCappuccinoContentPromise
- //------------------------------------------------------------------------------
-
- void CCappuccinoContentPromise::Fulfill( Environment* ev,
- ODStorageUnitView* promiseSUView )
- {
- ASSERT_NOT_NULL(promiseSUView);
-
- TempODValueType valueType = promiseSUView->GetType(ev);
- ODStorageUnit* su = promiseSUView->GetStorageUnit(ev);
-
- fContent->Fulfill(ev, su, valueType);
-
- Inherited::Fulfill(ev, promiseSUView);
- }
-
-